package com.mvu.banana.common.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mvu.banana.common.client.EvalService;
import com.mvu.banana.common.client.ValueDTO;
import com.mvu.banana.common.server.AJAXServlet;
import com.mvu.banana.common.server.ServletFactory;

/**
 * Created by IntelliJ IDEA.
 * User: mvu
 * Date: 4/10/11
 * Time: 1:06 AM
 * To change this template use File | Settings | File Templates.
 */
public class EvalServiceImpl extends RemoteServiceServlet implements EvalService {

  public ValueDTO getValues(ValueDTO state) {
    String dtoClassName = state.getClass().getName();
    AJAXServlet valueProvider = ServletFactory.instance().create(dtoClassName);
    if (valueProvider == null) {
      throw new IllegalStateException("Could not find var provider for: " + dtoClassName);
    }
    valueProvider.setRequest(this.getThreadLocalRequest());
    ValueDTO dto = valueProvider.post(state);
    return dto;
  }
}